package DAO;

import com.sel.modelo.Calendario;

import android.content.ContentValues;
import android.content.Context;

public class CalendarioDAO extends DAOGeneric<Calendario>{
    
    public static final String    TABELA = "calendario";
    public static final String[] COLUNAS = {"idcalendario", "evento", "data", "descricao", "campi", "status"};
    
    public static final String SCRIPT_CRIACAO_TABELA_CALENDARIO = "CREATE TABLE "+ TABELA +"( " +
                                                                      COLUNAS[0] +" INTEGER PRIMARY KEY," +
                                                                      COLUNAS[1] +" TEXT," +
                                                                      COLUNAS[2] +" TEXT UNIQUE NOT NULL, " +
                                                                      COLUNAS[3] +" TEXT," +
                                                                      COLUNAS[4] +" INTEGER," +
                                                                      COLUNAS[5] +" INTEGER" +
                                                                   ");";
    public static final String SCRIPT_DELECAO_TABELA_CALENDARIO = "DROP TABLE IF EXISTS "+TABELA;
    
    public static CalendarioDAO instance;
    
    public static CalendarioDAO getInstance(Context context) 
    {
        if(instance == null)
        {
            instance = new CalendarioDAO(context);
        }
        return instance;
    }

    public CalendarioDAO(Context context) 
    {
        super(context);
    }

    @Override
    public String getNomeColunaPrimaryKey() 
    {
        return COLUNAS[0];
    }

    @Override
    public String getNomeTabela() 
    {
        return TABELA;
    }

    @Override
    public ContentValues entidadeParacontentValues(Calendario calendario) 
    {
        ContentValues values = new ContentValues();
        if (calendario.getId()> 0)
        {
            values.put(COLUNAS[0], calendario.getId());
        }
        values.put(COLUNAS[1], calendario.getEvento());
        values.put(COLUNAS[2], calendario.getData());
        values.put(COLUNAS[3], calendario.getDescricao());
        values.put(COLUNAS[4], calendario.getCampi());
        values.put(COLUNAS[5], calendario.getStatus());
        return values;
    }

    @Override
    public Calendario contentValuesParaEntidade(ContentValues contentValues) 
    {
        Calendario calendario = new Calendario();
        calendario.setId(contentValues.getAsInteger(COLUNAS[0]));
        calendario.setEvento(contentValues.getAsString(COLUNAS[1]));
        calendario.setData(contentValues.getAsString(COLUNAS[2]));
        calendario.setDescricao(contentValues.getAsString(COLUNAS[3]));
        calendario.setCampi(contentValues.getAsInteger(COLUNAS[4]));
        calendario.setStatus(contentValues.getAsInteger(COLUNAS[5]));
        return calendario;
    }
}
